package com.imax.center.controller;

import com.github.xiaoymin.knife4j.core.util.StrUtil;
import com.imax.center.common.Result;
import com.imax.center.service.DeviceDataService;
import com.imax.center.tcp.TcpDataUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@Slf4j
@Api(tags = "测试接口")
@RestController
@RequestMapping("/api")
public class TestController {

    @Autowired
    DeviceDataService dataService;

    @ApiOperation(value = "测试写入数据到MQ", notes = "测试写入数据到MQ")
    @PostMapping("/testAddDataToMq")
    public Result<String> testAddDataToMq(String message, String pwd) throws InterruptedException {
        if (StrUtil.isBlank(message)) {
            return Result.error("message不能为空");
        }
        //验证密码是否正确
        if (!"Abcd@1234".equals(pwd)) {
            return Result.error("密码错误");
        }
        Map<String, Object> data = TcpDataUtil.parseData(message);
        dataService.syncHandlerEvent(message, data);
        return Result.success("ok");
    }

} 